// Forward rendering.
// Vertex shader.
//------------------------------------------

// Typedefs.
//------------------------------------------
struct Vertex
{
    float4 position : POSITION;
	float3 normal   : NORMAL;
};

struct Pixel
{
    float4 position             : SV_POSITION;
	float3 normal               : NORMAL;
	float3 world_view_direction : TEXCOORD0;
	float3 world_position       : TEXCOORD1;
};

// Globals.
//------------------------------------------
cbuffer FrameBuffer
{
	float4 world_camera_position;
	matrix world_matrix;
	matrix view_matrix;
	matrix projection_matrix;
};


Pixel Main(Vertex input)
{
    Pixel output;

	// Vertex position in combined coordinates.
	output.position = mul(float4(input.position.xyz, 1.0f), world_matrix);
	output.position = mul(output.position, view_matrix);
	output.position = mul(output.position, projection_matrix);
	
	// Normal in world coordinates.
    output.normal = mul(input.normal, (float3x3)world_matrix);
	output.normal = normalize(output.normal);

	// Vertex position in world coordinates.
	output.world_position = mul(input.position, (float3x3)world_matrix);
	
	// Compute view direction in world coordinates to that vertex.
	output.world_view_direction = world_camera_position - output.world_position;
	output.world_view_direction = normalize(output.world_view_direction);
	  
    return output;
}